import {getYMD,getNowFormatDate,getDay,formatGMTDate,sortBy} from '../../../../assets/js/util.js'

export default{
  data() {
    return{
      // 默认参数 和 URL
      SRC: '',
      DP: {
        p: '',
        f: '',
        uid: ''
      },
      prop: '',
      order: '', 
      ftitle:'',
      xlsxTitle:'',
      loading: false,
      searchable: false,
      pickerOptions: {
        shortcuts: [{
          text: '近7天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '近15天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '近30天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      title:'等级统计',
      activeIndex: "1",
      ruleForm :{
        sday:'',
        eday:'',
        day:'',
        startDate: '',
        nowDate:'',
        attr:'',
        platForm: '',
        agent: '',
        settlWay: '',
        channel: '',
        adPlace:''
      },
      tableHead1 :[{"prop":"0","label":"渠道",fixed: true},{"prop":"1","label":"新增账号",fixed: false},{"prop":"2","label":"1级",fixed: false},{"prop":"3","label":"2级",fixed: false},{"prop":"4","label":"3级",fixed: false},{"prop":"5","label":"4级",fixed: false},{"prop":"6","label":"5级",fixed: false},{"prop":"7","label":"6级",fixed: false},{"prop":"8","label":"7级",fixed: false},{"prop":"9","label":"8级",fixed: false},{"prop":"10","label":"9级",fixed: false},{"prop":"11","label":"10级",fixed: false},{"prop":"12","label":"11级",fixed: false},{"prop":"13","label":"12级",fixed: false},{"prop":"14","label":"13级",fixed: false},{"prop":"15","label":"14级",fixed: false},{"prop":"16","label":"15级"},{"prop":"17","label":"16级",fixed: false},{"prop":"18","label":"17级",fixed: false},{"prop":"19","label":"18级",fixed: false},{"prop":"20","label":"19级",fixed: false},{"prop":"21","label":"20级",fixed: false},{"prop":"22","label":"21级",fixed: false},{"prop":"23","label":"22级",fixed: false},{"prop":"24","label":"23级",fixed: false},{"prop":"25","label":"24级",fixed: false},{"prop":"26","label":"25级",fixed: false},{"prop":"27","label":"26级",fixed: false},{"prop":"28","label":"27级",fixed: false},{"prop":"29","label":"28级",fixed: false},{"prop":"30","label":"29级",fixed: false,fixed: false},{"prop":"31","label":"30级",fixed: false,fixed: false},{"prop":"32","label":"31级",fixed: false,fixed: false},{"prop":"33","label":"32级",fixed: false,fixed: false},{"prop":"34","label":"33级",fixed: false,fixed: false},{"prop":"35","label":"34级",fixed: false,fixed: false},{"prop":"36","label":"35级",fixed: false,fixed: false},{"prop":"37","label":"36级",fixed: false,fixed: false},{"prop":"38","label":"37级",fixed: false,fixed: false},{"prop":"39","label":"38级",fixed: false,fixed: false},{"prop":"40","label":"39级,fixed: false,fixed: false"},{"prop":"41","label":"40级",fixed: false,fixed: false,fixed: false},{"prop":"42","label":"41级",fixed: false,fixed: false},{"prop":"43","label":"42级",fixed: false},{"prop":"44","label":"43级",fixed: false},{"prop":"45","label":"44级",fixed: false},{"prop":"46","label":"45级",fixed: false},{"prop":"47","label":"46级",fixed: false},{"prop":"48","label":"47级",fixed: false},{"prop":"49","label":"48级",fixed: false},{"prop":"50","label":"49级",fixed: false},{"prop":"51","label":"50级",fixed: false},{"prop":"52","label":"51级",fixed: false},{"prop":"53","label":"52级",fixed: false},{"prop":"54","label":"53级",fixed: false},{"prop":"55","label":"54级",fixed: false},{"prop":"56","label":"55级",fixed: false},{"prop":"57","label":"56级",fixed: false,fixed: false},{"prop":"58","label":"57级",fixed: false},{"prop":"59","label":"58级",fixed: false},{"prop":"60","label":"59级",fixed: false},{"prop":"61","label":"60级",fixed: false},{"prop":"62","label":"61级",fixed: false}],
      tabHdD1S:['accounts','macs'],
      tableDataAll1:[],
      tableData1p:[],
      tableData1: [],
      tableData3: [],      
      /*当前页显示数量*/
      pageSize: 10,
      /*每页显示的数量*/
      pageSizes: [10, 20, 50, 100],
      /*dataTotal表数量*/
      dataTotal: 0,
      /*分页器*/
      currentPage: 1,
      // 归属
      attrs:[],
      // 渠道名称
      channels:[],
      // 代理商
      agents:[],
      // 平台
      platForms:[],
      // 结算方式
      settlWays:[],
      // 广告位置
      adPlaces:[]
    }
  }, 
  computed:{
   	// 	xlsx(){
		//   return this.title+'-'+this.ftitle+'.xlsx'
		// } 
  },
  methods: {
    // 通用 成功 与 失败
    successFun(data) {
      this.$message({
        message: data,
        type: 'success'
      });
    },
    errorFun(data) {
      this.$message.error(data);
    },
    dateChange(val){
      if(val){
        var val = val.split(" ");
        this.sday = val[0];
        this.eday = val[2];
      }
    },
    nowChange(val){
      if(val){
        this.day = val;
      }
    },
    // 表格下载
    excel(tableIndex,sheet) {
      var that = this;
      console.log(that.ftitle)
      // var a1 = that.sday.replace(/(\d+)\-(\d+)\-(\d+)/g,"$1/$2/$3");
      // var a2 =that.eday.replace(/(\d+)\-(\d+)\-(\d+)/g,"$1/$2/$3");
      var a1,a2 = "";
      if(that.activeIndex=='1'){
        that.xlsxTitle = "等级统计-"+that.ftitle+'-'+a1+'-'+a2
      }else if(that.activeIndex=='2'){
        that.xlsxTitle = "等级统计-"+that.ftitle+'-'+a1+'-'+a2
      }
      that["tableDataAll1"].accounts.push(that["tableData3"]);
      that.downloadExl(that["tableHead1"],that["tableDataAll1"].accounts,that.xlsxTitle,sheet);
       
    },
    agentChange(){

    },
    attrChange(){

    },
    channelChange(){

    },
    settlWayChange(){

    },
    adPlaceChange(){

    },
    loads() {
      this.loading = !this.loading; //加载中
      this.searchable = !this.searchable; //查询按钮不可用
    },
    search(){
      this.loads()
      this.apiAjax(this.sday,this.eday,this.day)
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.tableData1p = sortBy(this.tableData1p,this.prop,this.order);
      this.dataTotal = this.tableData1p.length;
      this.tableData1 = this.tableData1p.slice((this.currentPage-1)*(this.pageSize),this.currentPage*this.pageSize);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.tableData1p = sortBy(this.tableData1p,this.prop,this.order);
      this.dataTotal1= this.tableData1p.length;
      this.tableData1 = this.tableData1p.slice((this.currentPage-1)*(this.pageSize),this.currentPage*this.pageSize);
    },
    edit (){

    },
    handleDelete (){

    },
    getData(){

    },
    tabHdD1(o){
      if(o == 1){
        this.tableHead1 = [{"prop":"0","label":"渠道",fixed: true},{"prop":"1","label":"新增账号",fixed: false},{"prop":"2","label":"1级",fixed: false},{"prop":"3","label":"2级",fixed: false},{"prop":"4","label":"3级",fixed: false},{"prop":"5","label":"4级",fixed: false},{"prop":"6","label":"5级",fixed: false},{"prop":"7","label":"6级",fixed: false},{"prop":"8","label":"7级",fixed: false},{"prop":"9","label":"8级",fixed: false},{"prop":"10","label":"9级",fixed: false},{"prop":"11","label":"10级",fixed: false},{"prop":"12","label":"11级",fixed: false},{"prop":"13","label":"12级",fixed: false},{"prop":"14","label":"13级",fixed: false},{"prop":"15","label":"14级",fixed: false},{"prop":"16","label":"15级"},{"prop":"17","label":"16级",fixed: false},{"prop":"18","label":"17级",fixed: false},{"prop":"19","label":"18级",fixed: false},{"prop":"20","label":"19级",fixed: false},{"prop":"21","label":"20级",fixed: false},{"prop":"22","label":"21级",fixed: false},{"prop":"23","label":"22级",fixed: false},{"prop":"24","label":"23级",fixed: false},{"prop":"25","label":"24级",fixed: false},{"prop":"26","label":"25级",fixed: false},{"prop":"27","label":"26级",fixed: false},{"prop":"28","label":"27级",fixed: false},{"prop":"29","label":"28级",fixed: false},{"prop":"30","label":"29级",fixed: false,fixed: false},{"prop":"31","label":"30级",fixed: false,fixed: false},{"prop":"32","label":"31级",fixed: false,fixed: false},{"prop":"33","label":"32级",fixed: false,fixed: false},{"prop":"34","label":"33级",fixed: false,fixed: false},{"prop":"35","label":"34级",fixed: false,fixed: false},{"prop":"36","label":"35级",fixed: false,fixed: false},{"prop":"37","label":"36级",fixed: false,fixed: false},{"prop":"38","label":"37级",fixed: false,fixed: false},{"prop":"39","label":"38级",fixed: false,fixed: false},{"prop":"40","label":"39级,fixed: false,fixed: false"},{"prop":"41","label":"40级",fixed: false,fixed: false,fixed: false},{"prop":"42","label":"41级",fixed: false,fixed: false},{"prop":"43","label":"42级",fixed: false},{"prop":"44","label":"43级",fixed: false},{"prop":"45","label":"44级",fixed: false},{"prop":"46","label":"45级",fixed: false},{"prop":"47","label":"46级",fixed: false},{"prop":"48","label":"47级",fixed: false},{"prop":"49","label":"48级",fixed: false},{"prop":"50","label":"49级",fixed: false},{"prop":"51","label":"50级",fixed: false},{"prop":"52","label":"51级",fixed: false},{"prop":"53","label":"52级",fixed: false},{"prop":"54","label":"53级",fixed: false},{"prop":"55","label":"54级",fixed: false},{"prop":"56","label":"55级",fixed: false},{"prop":"57","label":"56级",fixed: false,fixed: false},{"prop":"58","label":"57级",fixed: false},{"prop":"59","label":"58级",fixed: false},{"prop":"60","label":"59级",fixed: false},{"prop":"61","label":"60级",fixed: false},{"prop":"62","label":"61级",fixed: false}];
        this.activeIndex = '1';
       // document.querySelector("#scrollAW .el-table__footer-wrapper").style.display="block";
       // document.getElementById("aa1").scrollLeft = 0;
       this.ftitle = "账号统计"

      }else if(o == 2){
        this.tableHead1 = [{"prop":"0","label":"渠道",fixed: true},{"prop":"1","label":"新增设备",fixed: false},{"prop":"2","label":"1级",fixed: false},{"prop":"3","label":"2级",fixed: false},{"prop":"4","label":"3级",fixed: false},{"prop":"5","label":"4级",fixed: false},{"prop":"6","label":"5级",fixed: false},{"prop":"7","label":"6级",fixed: false},{"prop":"8","label":"7级",fixed: false},{"prop":"9","label":"8级",fixed: false},{"prop":"10","label":"9级",fixed: false},{"prop":"11","label":"10级",fixed: false},{"prop":"12","label":"11级",fixed: false},{"prop":"13","label":"12级",fixed: false},{"prop":"14","label":"13级",fixed: false},{"prop":"15","label":"14级",fixed: false},{"prop":"16","label":"15级"},{"prop":"17","label":"16级",fixed: false},{"prop":"18","label":"17级",fixed: false},{"prop":"19","label":"18级",fixed: false},{"prop":"20","label":"19级",fixed: false},{"prop":"21","label":"20级",fixed: false},{"prop":"22","label":"21级",fixed: false},{"prop":"23","label":"22级",fixed: false},{"prop":"24","label":"23级",fixed: false},{"prop":"25","label":"24级",fixed: false},{"prop":"26","label":"25级",fixed: false},{"prop":"27","label":"26级",fixed: false},{"prop":"28","label":"27级",fixed: false},{"prop":"29","label":"28级",fixed: false},{"prop":"30","label":"29级",fixed: false,fixed: false},{"prop":"31","label":"30级",fixed: false,fixed: false},{"prop":"32","label":"31级",fixed: false,fixed: false},{"prop":"33","label":"32级",fixed: false,fixed: false},{"prop":"34","label":"33级",fixed: false,fixed: false},{"prop":"35","label":"34级",fixed: false,fixed: false},{"prop":"36","label":"35级",fixed: false,fixed: false},{"prop":"37","label":"36级",fixed: false,fixed: false},{"prop":"38","label":"37级",fixed: false,fixed: false},{"prop":"39","label":"38级",fixed: false,fixed: false},{"prop":"40","label":"39级,fixed: false,fixed: false"},{"prop":"41","label":"40级",fixed: false,fixed: false,fixed: false},{"prop":"42","label":"41级",fixed: false,fixed: false},{"prop":"43","label":"42级",fixed: false},{"prop":"44","label":"43级",fixed: false},{"prop":"45","label":"44级",fixed: false},{"prop":"46","label":"45级",fixed: false},{"prop":"47","label":"46级",fixed: false},{"prop":"48","label":"47级",fixed: false},{"prop":"49","label":"48级",fixed: false},{"prop":"50","label":"49级",fixed: false},{"prop":"51","label":"50级",fixed: false},{"prop":"52","label":"51级",fixed: false},{"prop":"53","label":"52级",fixed: false},{"prop":"54","label":"53级",fixed: false},{"prop":"55","label":"54级",fixed: false},{"prop":"56","label":"55级",fixed: false},{"prop":"57","label":"56级",fixed: false,fixed: false},{"prop":"58","label":"57级",fixed: false},{"prop":"59","label":"58级",fixed: false},{"prop":"60","label":"59级",fixed: false},{"prop":"61","label":"60级",fixed: false},{"prop":"62","label":"61级",fixed: false}];
        this.activeIndex = '2';
       // document.querySelector("#scrollAW .el-table__footer-wrapper").style.display="none";
      //  document.getElementById("aa1").scrollLeft = 0;
      this.ftitle = "设备统计"
      }
      this.tableData1p = this.tableDataAll1[''+this.tabHdD1S[o-1]+''];
      this.dataTotal = this.tableData1p.length;
      this.currentPage = 1;
      this.tableData1 = this.tableData1p.slice((this.currentPage-1)*(this.pageSize),this.currentPage*this.pageSize);
    //   setTimeout(function(){
    //     document.querySelector("#scrollAW").style.width = document.querySelector("#scrollAW .el-table__header").style.width
    //   },200)
          
    },
    // arrTojs
    getArrJson(arr){
      var arrNew = [];
      for(var i=0;i<arr.length;i++){
        var obj ={};
        obj.id = arr[i];
        obj.agentName = arr[i];
        arrNew.push(obj);
      }
      return arrNew;
    },
    // 获取选择信息
    getData(){
      this.$http.jsonp(`${this.SRC}data/get.do?p=${this.DP.p}&f=${this.DP.f}&a=initParam`,{
        params: {'ps':`uid=${this.DP.uid}`}
      }).then(function(res){
        var data =  JSON.parse(JSON.parse(res.body));
        if(data.res == "0"){
          this.agents = this.getArrJson(data.agent);
          this.platForms = this.getArrJson(data.platform);
          this.settlWays = this.getArrJson(data.paytype);
          this.channels = this.getArrJson(data.channelName);
        }else{
          this.errorFun(data['msg'])
        }
      }).catch(function(res){
        console.log(res)
      })
    },
    findData (data){
      this.loads();
      this.sday = formatGMTDate(new Date(new Date().getTime() - 1000*60*60*24*1),true,true);
      this.eday = formatGMTDate(new Date(new Date().getTime() - 1000*60*60*24*1),true,true);
      this.day = formatGMTDate(new Date(new Date().getTime() - 1000*60*60*24*1),true,true);
      this.ruleForm.startDate = [this.sday,this.eday];
      this.ruleForm.nowDate = this.day;
      this.apiAjax(this.sday,this.eday,this.day)
    },
    apiAjax(sday,eday,day){
      this.$http.jsonp(`${this.SRC}data/get.do?p=${this.DP.p}&f=${this.DP.f}&a=search`,{
        params: {'ps':`sday=${sday}&eday=${eday}&day=${day}&agent=${this.ruleForm.agent}&platform=${this.ruleForm.platForm}&channelName=${this.ruleForm.channel}&paytype=${this.ruleForm.settlWay}&uid=${this.DP.uid}`}
      }).then(function(res){
        this.loads();
        var data = JSON.parse(JSON.parse(res.body));
        if(parseInt(data['res']) === 0){


          this.tableDataAll1['accounts'] = data.accounts;
          this.tableDataAll1['macs'] = data.macs;
          

          this.tabHdD1(1)
        }else{
          this.errorFun(data['msg'])
        }
      }).catch(function(res){})
    },
    sortChage1({ column, prop, order }){
      this.prop = prop;
      this.order = order;
      if(this.tableData1p.slice().length>0){
        this.tableData1p = this.tableData1p.slice();
        this.tableData1p = sortBy(this.tableData1p,this.prop,this.order);
        this.currentPage= 1;
        this.tableData1 =this.tableData1p.slice((this.currentPage-1)*(this.pageSize),this.currentPage*this.pageSize);
        this.dataTotal = this.tableData1p.length;
      }
    }
  },
  mounted() {
    // 初始化URL
    this.SRC = this.$store.getters.src;
    this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
    this.DP.f = localStorage.getItem('ZULONGBIPAGEID');
    this.DP.uid = localStorage.getItem('ZULONGBIUSERID');
    this.getData();
    this.findData(0);  
  }
}